package com.ruoyi.parcel.service.impl;

import java.util.List;
import java.util.Random;

import cn.hutool.core.util.NumberUtil;
import com.ruoyi.parcel.util.AliyunSmsUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;
import com.ruoyi.parcel.mapper.EPackageTableMapper;
import com.ruoyi.parcel.domain.EPackageTable;
import com.ruoyi.parcel.service.IEPackageTableService;

/**
 * EPackageTableService业务层处理
 *
 * @author ruoyi
 * @date 2024-11-22
 */
@Service
@Slf4j
public class EPackageTableServiceImpl implements IEPackageTableService
{
    @Autowired
    private EPackageTableMapper ePackageTableMapper;
    @Autowired
    private AliyunSmsUtil aliyunSmsUtil;
    @Autowired
    private RedisTemplate redisTemplate;
    /**
     * 查询EPackageTable
     *
     * @param id EPackageTable主键
     * @return EPackageTable
     */
    @Override
    public EPackageTable selectEPackageTableById(Long id)
    {
        return ePackageTableMapper.selectEPackageTableById(id);
    }

    /**
     * 查询EPackageTable列表
     *
     * @param ePackageTable EPackageTable
     * @return EPackageTable
     */
    @Override
    public List<EPackageTable> selectEPackageTableList(EPackageTable ePackageTable)
    {
        return ePackageTableMapper.selectEPackageTableList(ePackageTable);
    }

    /**
     * 新增EPackageTable
     *
     * @param ePackageTable EPackageTable
     * @return 结果
     */
    @Override
    public int insertEPackageTable(EPackageTable ePackageTable)
    {
        return ePackageTableMapper.insertEPackageTable(ePackageTable);
    }

    /**
     * 修改EPackageTable
     *
     * @param ePackageTable EPackageTable
     * @return 结果
     */
    @Override
    public int updateEPackageTable(EPackageTable ePackageTable)
    {
        return ePackageTableMapper.updateEPackageTable(ePackageTable);
    }

    /**
     * 批量删除EPackageTable
     *
     * @param ids 需要删除的EPackageTable主键
     * @return 结果
     */
    @Override
    public int deleteEPackageTableByIds(Long[] ids)
    {
        return ePackageTableMapper.deleteEPackageTableByIds(ids);
    }

    /**
     * 删除EPackageTable信息
     *
     * @param id EPackageTable主键
     * @return 结果
     */
    @Override
    public int deleteEPackageTableById(Long id)
    {
        return ePackageTableMapper.deleteEPackageTableById(id);
    }

    @Override
    public String sendSms(String phoneNumber, String PickUpCode) {
        String o = (String) redisTemplate.opsForValue().get("sms");
        if(o==null){
            int[] ints = NumberUtil.generateRandomNumber(100000, 999999,1);
            PickUpCode = String.valueOf(ints[0]);
            System.out.println("生成的验证码："+PickUpCode);
             aliyunSmsUtil.sendSms(phoneNumber,PickUpCode);
             return PickUpCode;
        }else{
              aliyunSmsUtil.sendSms(phoneNumber,o);
            return o;
        }

    }



}
